home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / system / devlod.zip / DEVLOD.FIG < prev    next >
Text File  |  1990-12-06  |  27KB  |  839 lines

  1. Figure 1: Basic Structure of DEVLOD
  2.  
  3.  
  4. startup code (C0.ASM)
  5. main (DEVLOD.C)
  6.     Move_Loader
  7.         movup (MOVUP.ASM)
  8.     Load_Drvr
  9.         INT 21h Function 4B03h (Load Overlay)
  10.     Get_List
  11.         INT 21h Function 52h (Get List of Lists)
  12.         based on DOS version number:
  13.             get number of block devices
  14.             get value of LASTDRIVE
  15.             get Current Directory Structure (CDS) base
  16.             get pointer to NUL device
  17.     Init_Drvr
  18.         call DD init routine
  19.             build command packet
  20.             call Strategy
  21.             call Interrupt
  22.     Get_Out
  23.         if block device:
  24.             Put_Blk_Dev
  25.                 for each unit:
  26.                     Next_Drive
  27.                         get next available drive letter
  28.                     INT 21h Function 32h (Get DPB)
  29.                     INT 21h Function 53h (Translate BPB -> DPB)
  30.                     poke CDS
  31.                     link into DPB chain
  32.         Fix_DOS_Chain
  33.             link into dev chain
  34.         release environment space
  35.         INT 21h Function 31h (TSR)
  36.  
  37.  
  38. -----------------------------------------------------------------------------
  39.  
  40. Figure 2: Loading Device Drivers
  41.  
  42.  
  43. C:\UNDOC\KYLE>devlod \dos\smartdrv.sys 256 /a
  44. Microsoft SMARTDrive Disk Cache version 3.03
  45.     Cache size: 256K in Expanded Memory
  46.     Room for 30 tracks of 17 sectors each
  47.     Minimum cache size will be 0K
  48.  
  49. C:\UNDOC\KYLE>devlod \dos\ramdrive.sys
  50. Microsoft RAMDrive version 3.04 virtual disk D:
  51.     Disk size: 64k
  52.     Sector size: 512 bytes
  53.     Allocation unit: 1 sectors
  54.     Directory entries: 64
  55.  
  56. C:\UNDOC\KYLE>devlod \dos\vdisk.sys
  57. VDISK Version 3.2 virtual disk E:
  58.    Buffer size adjusted
  59.    Sector size adjusted
  60.    Directory entries adjusted
  61.    Buffer size:         64 KB
  62.    Sector size:        128
  63.    Directory entries:   64
  64.  
  65. C:\UNDOC\KYLE>devlod \dos\ansi.sys
  66.  
  67. C:\UNDOC\KYLE>mem
  68. Seg     Owner   Size           Env
  69. 09F3    0008    00F4 (  3904)        config [15 2F 4B 67 ]
  70. 0AE8    0AE9    00D3 (  3376)  0BC1  c:\dos33\command.com   [22 23 24 2E ]
  71. 0BBC    0000    0003 (    48)        free 
  72. 0BC0    0AE9    0019 (   400)            
  73. 0BDA    0AE9    0004 (    64)            
  74. 0BDF    3074    000D (   208)            
  75. 0BED    0000    0000 (     0)        free 
  76. 0BEE    0BEF    0367 ( 13936)  0BE0   \msc\bin\smartdrv.sys 256 /a [13 19 ]
  77. 0F56    0F57    1059 ( 66960)  0BE0   \msc\bin\ramdrive.sys  [F1 FA ]
  78. 1FB0    1FB1    104C ( 66752)  0BE0   \dos33\vdisk.sys  
  79. 2FFD    2FFE    0075 (  1872)  0BE0   \dos33\ansi.sys  [1B 29 ]
  80. 3073    3074    1218 ( 74112)  0BE0  C:\UNDOC\KYLE\MEM.EXE   [00 ]
  81. 428C    0000    7573 (481072)        free [30 F8 ]
  82.  
  83. C:\UNDOC\KYLE>dev
  84. NUL     
  85. CON     
  86. Block: 1 unit(s)
  87. Block: 1 unit(s)
  88. SMARTAAR
  89. QEMM386$
  90. EMMXXXX0
  91. CON     
  92. AUX     
  93. PRN     
  94. CLOCK$  
  95. Block: 3 unit(s)
  96. COM1    
  97. LPT1    
  98. LPT2    
  99. LPT3    
  100. COM2    
  101. COM3    
  102. COM4
  103.  
  104. -----------------------------------------------------------------------------
  105.  
  106. Sidebar
  107.  
  108. Some DOS and BIOS Data Structures
  109.  
  110.  
  111. BPB     BIOS uses the BPB (Bios Parameter Block) to learn the format of a
  112.         block device. Normally, the BPB is part of a physical disk's boot
  113.         record, and contains information such as the number of bytes
  114.         in a sector, the number of root directory entries, the number of
  115.         sectors taken by the File Allocation Table (FAT), etc.
  116.  
  117. CDS     The CDS (Current Directory Structure) is an undocumented array of
  118.         structures, sometimes also called the Drive Info Table, which
  119.         maintains the current state of each drive in the system. The array is
  120.         n elements long, where n equals LASTDRIVE.
  121.  
  122. DPB     For every block device (disk drive) in the system, there is a DPB
  123.         (Drive Parameter Block). These 32-byte blocks contain the information
  124.         that DOS uses to convert cluster numbers into Logical Sector Numbers,
  125.         and also associate the device driver for that device with its
  126.         assigned drive letter.
  127.  
  128. LoL     Probably the most commonly used undocumented DOS data structure,
  129.         the List of Lists is the DOS internal variable table, which includes,
  130.         amongst other things, the LASTDRIVE value, the head of the device
  131.         driver chain, and the CDS (Current Directory Structure). A pointer to
  132.         the LoL is returned in ES:BX by undocumented DOS Int 21h Function
  133.         52h.
  134.  
  135. ----------------------------------------------------------------------------
  136.  
  137. Listing 1
  138.  
  139.  
  140. /********************************************************************
  141.  *     DEVLOD.C - Jim Kyle - 08/20/90                               *
  142.  *            Copyright 1990 by Jim Kyle - All Rights Reserved      *
  143.  *     (minor revisions by Andrew Schulman - 9/12/90                *
  144.  *     Dynamic loader for device drivers                            *
  145.  *            Requires Turbo C; see DEVLOD.MAK also for ASM helpers.*
  146.  ********************************************************************/
  147.      
  148. #include <stdio.h>
  149. #include <stdlib.h>
  150. #include <dos.h>
  151.  
  152. typedef unsigned char BYTE;
  153.  
  154. #define GETFLAGS __emit__(0x9F)     /* if any error, quit right now */
  155. #define FIXDS    __emit__(0x16,0x1F)/* PUSH SS, POP DS              */
  156. #define PUSH_BP  __emit__(0x55)
  157. #define POP_BP   __emit__(0x5D)
  158.  
  159. unsigned _stklen = 0x200;
  160. unsigned _heaplen = 0;
  161.  
  162. char FileName[65];  /* filename global buffer                       */
  163. char * dvrarg;      /* points to char after name in cmdline buffer  */
  164. unsigned movsize;   /* number of bytes to be moved up for driver    */
  165. void (far * driver)();  /* used as pointer to call driver code      */
  166. void far * drvptr;  /* holds pointer to device driver               */
  167. void far * nuldrvr; /* additional driver pointers                   */
  168. void far * nxtdrvr;
  169. BYTE far * nblkdrs; /* points to block device count in List of Lists*/
  170. unsigned lastdrive; /* value of LASTDRIVE in List of Lists          */
  171. BYTE far * CDSbase; /* base of Current Dir Structure                */
  172. int CDSsize;        /* size of CDS element                          */
  173. unsigned nulseg;    /* hold parts of ListOfLists pointer            */
  174. unsigned nulofs;
  175. unsigned LoLofs;
  176.  
  177. #pragma pack(1)
  178.  
  179. struct packet{      /* device driver's command packet               */
  180.     BYTE hdrlen;
  181.     BYTE unit;
  182.     BYTE command;       /* 0 to initialize      */
  183.     unsigned status;    /* 0x8000 is error      */
  184.     BYTE reserv[8];
  185.     BYTE nunits;
  186.     unsigned brkofs;    /* break adr on return  */
  187.     unsigned brkseg;    /* break seg on return  */
  188.     unsigned inpofs;    /* SI on input          */
  189.     unsigned inpseg;    /* _psp on input        */
  190.     BYTE NextDrv;       /* next available drive */
  191.   } CmdPkt;
  192.   
  193. typedef struct {    /* Current Directory Structure (CDS)            */
  194.     BYTE path[0x43];
  195.     unsigned flags;
  196.     void far *dpb;
  197.     unsigned start_cluster;
  198.     unsigned long ffff;
  199.     unsigned slash_offset;  /* offset of '\' in current path field  */
  200.     // next for DOS4+ only
  201.     BYTE unknown;
  202.     void far *ifs;
  203.     unsigned unknown2;
  204.     } CDS;
  205.  
  206. extern unsigned _psp;       /* established by startup code in c0    */
  207. extern unsigned _heaptop;   /* established by startup code in c0    */
  208. extern BYTE _osmajor;       /* established by startup code      */
  209. extern BYTE _osminor;       /* established by startup code      */
  210.  
  211. void _exit( int );          /* established by startup code in c0    */
  212. void abort( void );         /* established by startup code in c0    */
  213.  
  214. void movup( char far *, char far *, int ); /* in MOVUP.ASM file     */
  215. void copyptr( void far *src, void far *dst ); /* in MOVUP.ASM file  */
  216.  
  217. void exit(int c)            /* called by startup code's sequence    */
  218. { _exit(c);}
  219.  
  220. int Get_Driver_Name ( void )
  221. { char *nameptr;
  222.   int i, j, cmdlinesz;
  223.  
  224.   nameptr = (char *)0x80;   /* check command line for driver name   */
  225.   cmdlinesz = (unsigned)*nameptr++;
  226.   if (cmdlinesz < 1)        /* if nothing there, return FALSE       */
  227.     return 0;
  228.   for (i=0; i<cmdlinesz && nameptr[i]<'!'; i++) /* skip blanks      */
  229.     ;
  230.   dvrarg = (ch